package com.cpj.bsyyzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cpj.bsyyzx.entity.Register;
import com.cpj.bsyyzx.entity.User;
import com.cpj.bsyyzx.mapper.RegisterMapper;
import com.cpj.bsyyzx.service.IRegisterService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@Service
public class RegisterServiceImpl extends ServiceImpl<RegisterMapper,Register> implements IRegisterService {

    @Override
    public Page pageList(Page page, Register register) {
        if(page == null){
            page = new Page();
        }

        QueryWrapper<Register> wrapper = new QueryWrapper<>();

        if(StringUtils.isNotBlank(register.getUserName())) {
            wrapper.like("user_name",register.getUserName());
        }

        // 如果分页返回 IPage 如果不分页 返回 List
        return super.page(page,wrapper);
    }

    @Override
    public IPage<Register> selectPageVo(Page<Register> page, Wrapper<Register> wrapper) {
        return getBaseMapper().selectPageVo(page,wrapper);
    }

    @Override
    public boolean batchdel(Integer[] ids) {
        List<Integer> list = new ArrayList<>(ids.length);
        Collections.addAll(list,ids);
        User user = new User();

        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.in("id",list);
        return this.removeByIds(list);

    }
}
